package com.jdiv.samples.tutor4;

import com.jdiv.JProcess;

//--------------------------------------------------------------------
//Process worm_segment
//Handles worm's body segments
//Entries: n        = Number of body (total=128)
//       priority = Priority of process in execution
//--------------------------------------------------------------------

public class WormSegment extends JProcess{
	
private int
 n;

public WormSegment(int n,int priority){
	this.n=n;
	this.priority=priority;

}
public void begin(){
    // If it is not the last body, creates another one with higher priority
    // and a minor number of body
   if (n>0) new WormSegment(n-1,priority+1); 
}

public void loop(){
    // Enters an endless loop

        // Checks priority which indicates tail's order
        // if it is within tail's length
        if (priority<Main.worm_length){
            // If it is within length, prints it
            graph=2;
        }else{
            // If not, doesn't put a graphic
            graph=0;
        }
        // Takes father's variables, the body that is ahead,
        // without refreshing, that means, where it was
        x=Main.father.x;
        y=Main.father.y;
      
  }
}